﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 可选值管理 添加 修改
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Web.Admin
{
    public partial class FormInputValue_save : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.SystemManage_ContentModel;
        }
        #endregion


        #region 页面变量
        FormInputValueManage m_FormInputValueManage = new FormInputValueManage();
        protected int m_id = 0;
        protected int m_cid = 0;
        protected int m_pid = 0;
        protected string m_title = "添加可选值";
        protected string m_parStr = "顶级可选值";
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strMSG = "名称";
            if (!PageAssist.CheckForm(txtName, ref strMSG))
            {
                Alert(strMSG);
                return;
            }
            int.TryParse(GetRequestViewState("id"), out m_id);
            int.TryParse(GetRequestViewState("cid"), out m_cid);
            int.TryParse(GetRequestViewState("pid"), out m_pid);
            FormInputValueInfo oFormInputValueInfo = (FormInputValueInfo)(GetPageViewState("model"));
            if (oFormInputValueInfo == null)
                oFormInputValueInfo = new FormInputValueInfo();
            else
                m_title = oFormInputValueInfo.Name;
            oFormInputValueInfo.Name = txtName.TextTrim.RemoveHtml();
            oFormInputValueInfo.FormInputValueTypeId = m_cid;
            oFormInputValueInfo.ParentId = m_pid;
            SubmitAlertAndParNewLocation(m_FormInputValueManage.Save(oFormInputValueInfo), "FormInputValueType_list.aspx?cid=" + m_cid.ToString() + "&id=" + m_id.ToString());
        }
        #endregion

        #region 页面方法
        public void LoadBase()
        {
            int.TryParse(InitRequestViewState("cid"), out m_cid);
            int.TryParse(InitRequestViewState("id"), out m_id);
            int.TryParse(InitRequestViewState("pid"), out m_pid);
            if (m_cid <= 0 || (new FormInputValueTypeManage()).GetInfoById(m_cid) == null)
            {
                Alert("请通过正确的路径进入本页");
            }
            FormInputValueInfo oFormInputValueInfo = m_FormInputValueManage.GetInfoById(m_id);
            InitPageViewState("model", oFormInputValueInfo);
            if (oFormInputValueInfo != null)
            {
                txtName.Text = oFormInputValueInfo.Name;
            }
            FormInputValueInfo oFormInputValueInfoTemp = m_FormInputValueManage.GetInfoById(m_pid);
            if (m_pid > 0 && oFormInputValueInfoTemp != null)
            {
                m_parStr = oFormInputValueInfoTemp.Name;
            }
        }
        #endregion
    }
}
